#include <iostream>
#include <thread>
#include "Ui.h"
#include "Pipe.h"

using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

void read();
void Loop();

Pipe * pipe;

int main(int argc, char** argv) {
	std::thread t1{[]() {
		read();
	}};
	std::thread t2{[]() {
		Loop();
	}};
	std::thread t3{[]() {
		Ui w(pipe);
	}};
	//thread t1=thread(read);//需要C++11标准
	//thread t2(Loop);
	pipe = new Pipe("PaddleOCR-json.exe");
	t1.join();
	t2.join();
	t3.join();
	return 0;
}

void read() {

	while (true) {
		char str[200];
		cin >> str;
		cout << " 发送 " << endl;
		pipe->sendCommand(str);//提交命令
	}
}

void Loop() {
	while (true) {
		Sleep(1000);
		if (pipe->getStatus() == -11) {
			cout << " ERROR " << endl;
			return;
		}
	}
}
